package idx

import (
	"hash"
	"io"
)

type hashWriter struct {
	writer io.Writer
	hash   hash.Hash
}

func NewHashWriter(writer io.Writer, hash hash.Hash) *hashWriter {
	return &hashWriter{writer: writer, hash: hash}
}

func (s *hashWriter) Write(b []byte) (int, error) {
	s.hash.Write(b)
	return s.writer.Write(b)
}

func (s *hashWriter) Hash() []byte {
	return s.hash.Sum(nil)
}
